﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Data;
using HospitalSystem.Core;


namespace HospitalSystem
{
    public partial class familyeditcarer : System.Web.UI.Page
    {
        private show_Image _showimage;
        private regfamilyLog _regf;
        protected void Page_Load(object sender, EventArgs e)
        {
            showsession();
            _showimage = new show_Image();
            _regf = new regfamilyLog();



            _showimage.show_Images(cid_label, Image1);

            if (Session["CID"] == null)
            {

                MessageBoxurl("กรุณากดค้นหา หรือลงทะเบียนเด็กก่อน", "findchild.aspx");

            }

            if (!IsPostBack)
            {
                _regf.radioLiveStatus(LiveStatus);
                _regf.dropdownMariageStatus(MariageStatus);
            
                _regf.loaddataCarer(cid_label, Name, LastName, CID, LiveStatus, Race, Religion, fcid, LiveHouseNumber, LiveHouseName, LiveHouseMoo, LiveHousesoy, LiveStreetName, Livetambon, LiveCity, LiveProvince, LivePostcode, CensusHouseNumber, CensusHouseName, CensusHouseMoo, CensusHousesoy, CensusStreetName, Censustambon, CensusCity, CensusProvince, CensusPostcode, IncomePerMonth, AddressOccupation, OherIncome, OherIncomeFrom, EduLevel, Occupation, MariageStatus, LastNation);
      
            }
        }



        private void MessageBoxurl(string msg, string urld)
        {
            Label lbl = new Label();
            lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "');" + "window.location.href='" + urld + "';" + "</script>";
            Page.Controls.Add(lbl);
        }
        protected void showsession()
        {
            String ShowValue = (string)Session["CID"];
            cid_label.Text = ShowValue;
            String ShowValue2 = (string)Session["LastName"];
            lname.Text = ShowValue2;

            String ShowValue3 = (string)Session["FirstName"];
            fname.Text = ShowValue3;

            String ShowValue4 = (string)Session["fCID"];
            fcid.Text = ShowValue4;

        }



        protected void familylist_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void RadioButton3_CheckedChanged(object sender, EventArgs e)
        {
            bindtextbox();
        }


        protected void bindtextbox()
        {
            Session["StreetAddress"] = CensusHouseNumber.Text;

            Session["moo"] = CensusHouseMoo.Text;
            Session["HomeName"] = CensusHouseName.Text;
            Session["Soy"] = CensusHousesoy.Text;

            Session["StreetName"] = CensusStreetName.Text;
            Session["tumbon"] = Censustambon.Text;
            Session["City"] = CensusCity.Text;
            Session["Province"] = CensusProvince.Text;
            Session["Postcode"] = CensusPostcode.Text;


            String StreetAddress = (string)Session["StreetAddress"];
            LiveHouseNumber.Text = StreetAddress;


            String moo = (string)Session["moo"];
            LiveHouseMoo.Text = moo;

            String HomeName = (string)Session["HomeName"];
            LiveHouseName.Text = HomeName;

            String Soy = (string)Session["Soy"];
            LiveHousesoy.Text = Soy;


            String StreetName = (string)Session["StreetName"];
            LiveStreetName.Text = StreetName;

            String tumbon = (string)Session["tumbon"];
            Livetambon.Text = tumbon;
            String City = (string)Session["City"];
            LiveCity.Text = City;
            String Province = (string)Session["Province"];
            LiveProvince.Text = Province;

            String Postcode = (string)Session["Postcode"];
            LivePostcode.Text = Postcode;


        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            _regf.insertregdataCarer(cid_label, Name.Text, LastName.Text, CID.Text, Race.Text, Religion.Text, LiveStatus, LiveHouseNumber.Text, LiveHouseName.Text, LiveHouseMoo.Text, LiveHousesoy.Text, LiveStreetName.Text, Livetambon.Text, LiveCity.Text, LiveProvince.Text, LivePostcode.Text, CensusHouseNumber.Text, CensusHouseName.Text, CensusHouseMoo.Text, CensusHousesoy.Text, CensusStreetName.Text, Censustambon.Text, CensusCity.Text, CensusProvince.Text, CensusPostcode.Text, IncomePerMonth.Text, EduLevel, AddressOccupation.Text, Occupation, OherIncome.Text, OherIncomeFrom.Text, fcid, MariageStatus, LastNation.Text);
            MessageBoxurl("เพิ่มผู้ดูแลหลักเรียบร้อย", "checkmember.aspx");
        }


        private void MessageBox(string msg)
        {
            Label lbl = new Label();
            lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "')</script>";
            Page.Controls.Add(lbl);



        }

    }
}